package com.ljh.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.google.common.collect.Lists;
import com.ljh.common.JsonData;
import com.ljh.pojo.OutTable;
import com.ljh.mapper.OutTableMapper;
import com.ljh.service.OUTTABLEervice;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ljh.utils.ExceptionUtils;
import com.ljh.vo.OutTableVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 刘剑鸿
 * @since 2021-10-29
 */
@Service
public class OutTableServiceImpl extends ServiceImpl<OutTableMapper, OutTable> implements OUTTABLEervice {

    @Autowired
    private OutTableMapper outTableMapper;
    public JsonData selectOutTable(OutTableVo outTableVo){
        Page<OutTable> page = PageHelper.startPage(outTableVo.getPage(),outTableVo.getLimit());
        List<OutTable> list1 = outTableMapper.selectOutList();
        if (CollectionUtils.isEmpty(list1)){
            list1 = Lists.newArrayList();
        }
        return JsonData.success(page.getTotal(),list1);
    }
    public void addOut(OutTable outTable){
        int row = outTableMapper.insertOut(outTable);
        if (row == 0 ){
            throw new ExceptionUtils("新增失败，插入数据库出错");
        }
    }
    public List<OutTable> selectOpen(){
        return outTableMapper.selectListIDandname();
    }
}
